#define _CRT_SECURE_NO_WARNINGS 
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
#include <array>
#include <time.h>
#include <queue>
using namespace std;

#include "BSTree.h"

//插入、遍历、删除
void TestBSTree()
{
	int a[] = { 8, 3, 1, 10, 6, 4, 7, 14, 13 };
	K::BSTree<int> t1;
	//插入建树
	for (auto e : a)
	{
		t1.Insert(e);
	}

	t1.InOrder();

	t1.Erase(4);
	t1.InOrder();

	t1.Erase(14);
	t1.InOrder();

	t1.Erase(3);
	t1.InOrder();

	t1.Erase(8);
	t1.InOrder();
}
//KV模型--简易字典
void TestBSTree2()
{
	KV::BSTree<string, string> Dictionary;
	Dictionary.Insert("sort", "排序");
	Dictionary.Insert("left", "左边");
	Dictionary.Insert("right", "右边");
	Dictionary.Insert("string", "字符串");
	Dictionary.Insert("insert", "插入");
	Dictionary.Insert("erase", "删除");

	string str;
	while (cin >> str)
	{
		auto ret = Dictionary.Find(str);
		if (ret)
		{
			cout <<str << ":" << ret->_value << endl;
		}
		else
		{
			cout << "无此单词" << endl;
		}
	}
}
//KV模型--水果统计树
void TestBSTree3()
{
	string arr[] = { "西瓜", "西瓜", "苹果", "西瓜", "苹果", "苹果", "西瓜", "苹果", "香蕉", "苹果", "香蕉", "梨" };

	KV::BSTree<string, int> countTree;
	for (auto str : arr)
	{
		//KV::BSTreeNode<string, int>* 
		auto ret = countTree.Find(str);
		if (ret == nullptr)
		{
			countTree.Insert(str, 1);
		}
		else
		{
			ret->_value++;
		}
	}

	countTree.InOrder();
}

int main()
{
	TestBSTree3();
	return 0;
}
